package dao;

import util.DBMannager;
import entity.Vegetable;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class VegetableSelectDao {


    public List<Vegetable> findAll() throws SQLException {

        List<Vegetable> vegetableList = new ArrayList<Vegetable>();
        Connection connection = DBMannager.getConnection();
        String sql = "select * from vegetable";


        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            ps = connection.prepareStatement(sql);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        try {
            rs=ps.executeQuery();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        while (rs.next()){
            Vegetable vegetable = new Vegetable();
            vegetable.setVegename(rs.getString("vegename"));
            vegetable.setPlanttime(rs.getDate("planttime"));
            vegetable.setNumber(rs.getInt("number"));
            vegetable.setVstatus(rs.getInt("vstatus"));
            vegetable.setPrice(rs.getBigDecimal("price"));
            vegetableList.add(vegetable);
        }

        return vegetableList;
    }


}
